package com.kmzx.one.project.controller;

import com.kmzx.one.project.net.BaseResult;
import com.kmzx.one.project.others.common.FeeData;
import com.kmzx.one.project.others.dto.EntryFeeInfo;
import com.kmzx.one.project.others.dto.FastProdMainInfo;
import com.kmzx.one.project.others.dto.FastZoneInfo;
import com.kmzx.one.project.others.dto.FastZoneOutInfo;
import com.kmzx.one.project.others.dto.MemberActionInfo;
import com.kmzx.one.project.others.dto.ProdCateOutInfo;
import com.kmzx.one.project.others.dto.ProdMainInfo;
import com.kmzx.one.project.others.dto.ProdOutInfo;
import com.kmzx.one.project.others.dto.ProdSpecsInfo;
import com.kmzx.one.project.others.vos.ChargesFee;
import com.kmzx.one.project.service.FeeService;
import com.kmzx.one.project.service.ProdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Api(tags = "快美甄选_[ 商品_接口 ]")
@RestController
public class ProdController extends BaseController {

    @Autowired
    private ProdService prodService;

    @Autowired
    FeeService feeService;

    @ApiOperation(value = "1.商品分类列表", notes = "1.商品分类列表")
    @GetMapping(value = "goods/allCategory")
    public BaseResult findCateAll(String userId) {
        try {
            List<ProdCateOutInfo> all = prodService.findCateAll(userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(all);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }


    /**
     * 展示商品列表下的商品
     *
     * @return
     */
    @ApiOperation(value = "2.由类别Id 查找 该类别下的 商品 ", notes = "由 商品类别Id 查找 该类别下的 商品 ")
    @GetMapping(value = "goods/listByCateId")
    public BaseResult listGoodsByCateId(@RequestParam("cateId") Integer cateId,
                                        @RequestParam("pageNum") Integer pageNum,
                                        @RequestParam("pageSize") Integer pageSize, String userId) {
        try {
            List<ProdOutInfo> all = prodService.findProdByCateIdPager();
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(all);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

    /**
     * 展示商品主要属性
     *
     * @return
     */
    @ApiOperation(value = "3.由 商品Id 查找 该商品 主要信息", notes = "由 商品Id 查找 该商品 主要信息")
    @GetMapping(value = "goods/listByGoodsId")
    public BaseResult findGoodsById(String goodsId, String userId) {
        try {
            ProdMainInfo info = prodService.findProdMainInfo(goodsId, userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(info);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }


    /**
     * 展示商品主要其他属性
     *
     * @return
     */
    @ApiOperation(value = "4.展示商品的 颜色,尺码 等详细信息", notes = "展示商品的 颜色,尺码 等详细信息")
    @GetMapping(value = "goods/detailByGoodsId")
    public BaseResult findGoodsDetailById(String goodsId, String userId, String fastId, Integer io) {
        try {
            ProdSpecsInfo detail = prodService.findProdEntryInfo(goodsId, userId, fastId, io);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(detail);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

    /**
     * 分享商品
     *
     * @param goodsId
     * @param userId
     * @return
     */

    @ApiOperation(value = "5.分享商品", notes = "分享商品")
    @GetMapping(value = "goods/shareGoods")
    public BaseResult shareGoods(String goodsId, String userId, String fast) {
        try {
            String detail = prodService.doShareGoods(userId, goodsId, fast);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(detail);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

    @ApiOperation(value = "6.由二维码图片获取商品", notes = "由二维码图片获取商品")
    @GetMapping(value = "goods/byScene")
    public BaseResult sceneToProduct(String scene) {
        try {
            Map<String, String> detail = prodService.doSceneToProduct(scene);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(detail);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

    @ApiOperation(value = "7.获取商品的包邮资费信息", notes = "获取商品的包邮资费信息")
    @GetMapping(value = "goods/free")
    public BaseResult getProductFreeFee(Integer tradeType,String code){
        try {
            EntryFeeInfo info = feeService.findEntryFeeInfo(tradeType, code);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(info);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }

    @ApiOperation(value = "8.获取商品的包邮资费信息", notes = "获取商品的包邮资费信息")
    @GetMapping(value = "goods/fee")
    public BaseResult getProductFee(Integer tradeType,String code) {
//        try {
//            List<FeeData> detail = prodService.findProductDifferentFee();
//            BaseResult success = BaseResult.Builder.SUCC().initSuccData(detail);
//            return success;
//        } catch (Exception e) {
//            return handleException(e);
//        }

        try {
            EntryFeeInfo info = feeService.findEntryFeeInfo(tradeType, code);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(info);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }


    // findFastZone
    @ApiOperation(value = "9.商品直升专区", notes = "商品直升专区")
    @GetMapping(value = "goods/fast")
    public BaseResult aToFastZone(String userId) {
        try {
            FastZoneOutInfo info = prodService.findFastZone(userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(info);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }


    @ApiOperation(value = "10.商品直升专区,列表主信息", notes = "10.商品直升专区,列表主信息")
    @GetMapping(value = "goods/fastMain")
    public BaseResult fastVipDetail(String fastId, String userId, Integer pageNum, Integer pageSize) {
        try {
            pageNum = pageNum == null ? super.pageNum : pageNum;
            pageSize = pageSize == null ? super.pageSize : pageSize;
            FastZoneInfo detail = prodService.findStraightListProduct(fastId, userId, pageNum, pageSize);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(detail);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }



    /**
     * 展示商品主要属性
     *
     * @return
     */
    @ApiOperation(value = "11.商品直升专区,信息", notes = "由 商品Id 查找 该商品 主要信息")
    @GetMapping(value = "goods/fastByGoodsId")
    public BaseResult findFastGoodsById(String goodsId, String userId) {
        try {
            FastProdMainInfo info = prodService.selectFastProdMainInfo(goodsId, null, userId);
            BaseResult success = BaseResult.Builder.SUCC().initSuccData(info);
            return success;
        } catch (Exception e) {
            return handleException(e);
        }
    }



}
